import 'package:flutter/material.dart';
import 'package:flutter_ext/home/net/daily_list.dart';

class DailyPage extends StatefulWidget{
  @override
  State<StatefulWidget> createState() => new DailyPageState();
}

class DailyPageState extends State<DailyPage>{

  DateTime selectedDate = new DateTime.now();
  
  final String _url = 'http://gank.io/api/day';

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: const Text("-daily-"),
        actions: <Widget>[
          new Padding(padding: const EdgeInsets.all(4.0),
            child: new IconButton(
              icon: new Icon(Icons.calendar_today),
              onPressed: (){
                _selectedDate(context);
              },),
          ),
          new Padding(padding: const EdgeInsets.all(4.0),
            child: new IconButton(
                icon: new Icon(Icons.search),
                onPressed: (){

                },),),
        ],
      ),
        body: new DailyList(
            url:_url
                +'/'+selectedDate.year.toString()
                +'/'+selectedDate.month.toString()
                +'/'+selectedDate.day.toString()
        ));
  }


  // should add container of datePicker
  Future<Null> _selectedDate(BuildContext context) async {
    final DateTime picked = await showDatePicker(
        context: context,
        initialDate: selectedDate,
        firstDate: new DateTime(2008,8),
        lastDate: new DateTime(2120)
    );
    if (picked !=null && picked != selectedDate){
      setState((){
        selectedDate = picked;
      });
    }
  }

}

